﻿using System;

namespace DatabaseConnectionExample
{
    class DatabaseCommand
    {
        private readonly DatabaseConnection connection;
        private readonly string sqlExpression;

        public DatabaseCommand(string sql, DatabaseConnection dbConnection)
        {
            if(String.IsNullOrWhiteSpace(sql))
                throw new ArgumentException("SQL");
            sqlExpression = sql;

            if(dbConnection==null)
                throw new NullReferenceException("Database Connection");
            connection = dbConnection;
        }

        public void Execute()
        {
            connection.OpenConnection();
            Console.WriteLine("Execute SQL query: {0}", sqlExpression);
            connection.CloseConnection();
        }
    }
}